﻿#include "ListViewPropertyEditEntry.h"
#include <QListView>

#include "EnumEditEntry.h"
#include "BooleanEditEntry.h"
#include "IntegerEditEntry.h"
#include "SizeEditEntry.h"
#include "AlignmentEditEntry.h"

#include "ObjectPropertyEditEntryFactory.h"
REGISTER_PROPERTY_EDIT_ENTRY(ListView)

struct ListViewPropertyEditEntry::ListViewPropertyEditEntryPrivate {
    QPointer<QListView> listView;

    QPointer<EnumEditEntry> entryMovement;
    QPointer<EnumEditEntry> entryFlow;
    QPointer<BooleanEditEntry> entryIsWrapping;
    QPointer<EnumEditEntry> entryResizeMode;
    QPointer<EnumEditEntry> entryLayoutMode;
    QPointer<IntegerEditEntry> entrySpacing;
    QPointer<SizeEditEntry> entryGridSize;
    QPointer<EnumEditEntry> entryViewMode;
    QPointer<IntegerEditEntry> entryModelColumn;
    QPointer<BooleanEditEntry> entryUniformItemSize;
    QPointer<IntegerEditEntry> entryBatchSize;
    QPointer<BooleanEditEntry> entryWordWrap;
    QPointer<BooleanEditEntry> entrySelectionRectVisible;
    QPointer<AlignmentEditEntry> entryItemAlignment;
};

ListViewPropertyEditEntry::~ListViewPropertyEditEntry() { }

ListViewPropertyEditEntry::ListViewPropertyEditEntry(QWidget *parent) : PropertyEditEntry{parent} {
    p.reset(new ListViewPropertyEditEntryPrivate);
    initUi();
    retranslateUi();
}

ListViewPropertyEditEntry::ListViewPropertyEditEntry(void *object, QWidget *parent) : PropertyEditEntry{parent} {
    p.reset(new ListViewPropertyEditEntryPrivate);
    initUi();
    retranslateUi();
    setObject(object);
}

void ListViewPropertyEditEntry::setObject(void *object) {
    p->listView = static_cast<QListView*>(object);
}

void ListViewPropertyEditEntry::onTick() {
    const auto &view = p->listView;
    if(!view || !isVisible()) {
        return ;
    }

    p->entryMovement->setValue(view->movement());
    p->entryFlow->setValue(view->flow());
    p->entryIsWrapping->setValue(view->isWrapping());
    p->entryResizeMode->setValue(view->resizeMode());
    p->entryLayoutMode->setValue(view->layoutMode());
    p->entrySpacing->setValue(view->spacing());
    p->entryGridSize->setValue(view->gridSize());
    p->entryViewMode->setValue(view->viewMode());
    p->entryModelColumn->setValue(view->modelColumn());
    p->entryUniformItemSize->setValue(view->uniformItemSizes());
    p->entryBatchSize->setValue(view->batchSize());
    p->entryWordWrap->setValue(view->wordWrap());
    p->entrySelectionRectVisible->setValue(view->isSelectionRectVisible());
    p->entryItemAlignment->setValue(view->itemAlignment());
}

void ListViewPropertyEditEntry::initUi() {
    p->entryMovement = new EnumEditEntry;
    p->entryMovement->setMetaEnum(QMetaEnum::fromType<QListView::Movement>());
    appendChildEntry(p->entryMovement);

    p->entryFlow = new EnumEditEntry;
    p->entryFlow->setMetaEnum(QMetaEnum::fromType<QListView::Flow>());
    appendChildEntry(p->entryFlow);

    p->entryIsWrapping = new BooleanEditEntry;
    appendChildEntry(p->entryIsWrapping);

    p->entryResizeMode = new EnumEditEntry;
    p->entryResizeMode->setMetaEnum(QMetaEnum::fromType<QListView::ResizeMode>());
    appendChildEntry(p->entryResizeMode);

    p->entryLayoutMode = new EnumEditEntry;
    p->entryLayoutMode->setMetaEnum(QMetaEnum::fromType<QListView::LayoutMode>());
    appendChildEntry(p->entryLayoutMode);

    p->entrySpacing = new IntegerEditEntry;
    appendChildEntry(p->entrySpacing);

    p->entryGridSize = new SizeEditEntry;
    appendChildEntry(p->entryGridSize);

    p->entryViewMode = new EnumEditEntry;
    p->entryViewMode->setMetaEnum(QMetaEnum::fromType<QListView::ViewMode>());
    appendChildEntry(p->entryViewMode);

    p->entryModelColumn = new IntegerEditEntry;
    appendChildEntry(p->entryModelColumn);

    p->entryUniformItemSize = new BooleanEditEntry;
    appendChildEntry(p->entryUniformItemSize);

    p->entryBatchSize = new IntegerEditEntry;
    appendChildEntry(p->entryBatchSize);

    p->entryWordWrap = new BooleanEditEntry;
    appendChildEntry(p->entryWordWrap);

    p->entrySelectionRectVisible = new BooleanEditEntry;
    appendChildEntry(p->entrySelectionRectVisible);

    p->entryItemAlignment = new AlignmentEditEntry;
    appendChildEntry(p->entryItemAlignment);
}

void ListViewPropertyEditEntry::retranslateUi() {
    setTitle(tr("QListView"));
    p->entryMovement->setTitle(tr("movement"));
    p->entryFlow->setTitle(tr("flow"));
    p->entryIsWrapping->setTitle(tr("isWarpping"));
    p->entryResizeMode->setTitle(tr("resizeMode"));
    p->entryLayoutMode->setTitle(tr("layoutMode"));
    p->entrySpacing->setTitle(tr("spacing"));
    p->entryGridSize->setTitle(tr("gridSize"));
    p->entryViewMode->setTitle(tr("viewMode"));
    p->entryModelColumn->setTitle(tr("modelColumn"));
    p->entryUniformItemSize->setTitle(tr("uniformItemSize"));
    p->entryBatchSize->setTitle(tr("batchSize"));
    p->entryWordWrap->setTitle(tr("wordWrap"));
    p->entrySelectionRectVisible->setTitle(tr("selectionRectVisible"));
    p->entryItemAlignment->setTitle(tr("itemAlignment"));
}
